﻿using System.Web.Mvc;
using Abp.Application.Navigation;
using Abp.Localization;
using Abp.Runtime.Session;
using Abp.Threading;
using Laboratory.Web.Models.Layout;
using Laboratory.Users;
using System.Collections.Generic;
using Laboratory.Users.Dto;
using AutoMapper;
using System.Linq;

namespace Laboratory.Web.Controllers
{
    public class LayoutController : LaboratoryControllerBase
    {
        private readonly IUserNavigationManager _userNavigationManager;
        private readonly ILanguageManager _languageManager;
        private readonly IUserService _userSetvice;


        public LayoutController(
            IUserNavigationManager userNavigationManager, 
            ILocalizationManager localizationManager,
            ILanguageManager languageManager,
            IUserService user)
        {
            _userNavigationManager = userNavigationManager;
            _languageManager = languageManager;
            _userSetvice = user;
        }


        [ChildActionOnly]
        public PartialViewResult TopMenu(string activeMenu = "")
        {
            IEnumerable<MenuItemDto> menus = _userSetvice.GetMenuItems();

            UserMenuInfo mainMenu = new UserMenuInfo() {
                Name="MainMenu",
                Items= menus.ToList(),
                DisplayName= "Main menu"
            };



            var model = new TopMenuViewModel
                        {
                            MainMenu = mainMenu,
                            ActiveMenuItemName = activeMenu
                        };


            return PartialView("_TopMenu", model);
        }

        [ChildActionOnly]
        public PartialViewResult LanguageSelection()
        {
            var model = new LanguageSelectionViewModel
                        {
                            CurrentLanguage = _languageManager.CurrentLanguage,
                            Languages = _languageManager.GetLanguages()
                        };

            return PartialView("_LanguageSelection", model);
        }
    }
}